//
//  XJAfterSaleHistoryCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/20.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJAfterSaleHistoryCell.h"
@interface XJAfterSaleHistoryCell()
@property (weak, nonatomic) IBOutlet UILabel *SNLb; //1.订单号
@property (weak, nonatomic) IBOutlet UILabel *timeLb; //2.时间
@property (weak, nonatomic) IBOutlet UIImageView *iconIv;//3.图片
@property (weak, nonatomic) IBOutlet UILabel *nameLb; //4.名字
@property (weak, nonatomic) IBOutlet UILabel *countLb; //5.购买数量
@property (weak, nonatomic) IBOutlet UIButton *firstButton; //6.第一个按钮。默认隐藏
@property (weak, nonatomic) IBOutlet UIButton *secondButton;//7.第二个按钮。


@end
@implementation XJAfterSaleHistoryCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.iconIv.layer.masksToBounds = YES;
    self.iconIv.layer.cornerRadius = 5;
    
    
    self.firstButton.hidden = YES;
    
    self.secondButton.layer.masksToBounds = YES;
    self.secondButton.layer.cornerRadius = 15;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)setModel:(XJAfterSaleHistoryModel *)model {
    _model = model;
    
    self.SNLb.text = [NSString stringWithFormat:@"订单号%@",model.refund_sn];
    
    
    NSString *timeStr = [self timeFromStampStr:[NSString stringWithFormat:@"%@",model.create_time]];
    
    self.timeLb.text = timeStr;
    [self.iconIv sd_setImageWithURL:[NSURL URLWithString:model.cover]];
    self.nameLb.text = model.goods_name;
    
    [self.firstButton setTitle:model.btnText forState:(UIControlStateNormal)];
    
    XJLog(@"%@",[model.quantity class]); // __NSCFNumber
    //这个属性在赋值的时候 直接奔到
    //    self.countLb.text = model.quantity;//❌ 直接奔溃.
    self.countLb.text = [NSString stringWithFormat:@"数量%@",model.quantity];//✅
}

#pragma mark - 二 private method
- (NSString *)timeFromStampStr:(NSString *)stampStr {
    NSTimeInterval intervale = [stampStr doubleValue] / 1000.0;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:intervale];
    
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    [fmt setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    return [fmt stringFromDate:date];
}
@end
